package com.artPreter.service.impl;


import com.artPreter.mapper.OnlineTypeMapper;
import com.artPreter.pojo.OnlineType;
import com.artPreter.pojo.OnlineType;
import com.artPreter.service.IOnlineTypeService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

/**
 * <p>
 * 作品在线分类表 服务实现类
 * </p>
 *
 * @author jarvis
 * @since 2024-12-16
 */
@Service
public class OnlineTypeServiceImpl extends ServiceImpl<OnlineTypeMapper, OnlineType> implements IOnlineTypeService {

    @Override
    public IPage<OnlineType> getPage(Integer currentPage, Integer size, OnlineType onlineType) {
        IPage<OnlineType> onlineTypeIPage = new Page<>(currentPage, size);
        LambdaQueryWrapper<OnlineType> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(OnlineType::getStatus,1);
        if(onlineType.getName()!=null&&onlineType.getName()!=""){
            queryWrapper.like(OnlineType::getName,onlineType.getName());
        }
        onlineTypeIPage = this.baseMapper.selectPage(onlineTypeIPage, queryWrapper);
        return onlineTypeIPage;
    }

    @Override
    public void add(OnlineType onlineType) {
        onlineType.setStatus(1);
        // 生成UUID并设置到实体对象中
        String uuid = UUID.randomUUID().toString();
        onlineType.setTypeId(uuid);
        this.baseMapper.insert(onlineType);
    }

    @Override
    public void edit(OnlineType onlineType) {
        this.baseMapper.updateById(onlineType);
    }

    @Override
    public void delete(OnlineType onlineType) {
        onlineType.setStatus(0);
        this.baseMapper.updateById(onlineType);
    }

    @Override
    public List<OnlineType> getList(OnlineType onlineType) {
        LambdaQueryWrapper<OnlineType> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(OnlineType::getStatus,1);
        List<OnlineType> result= this.baseMapper.selectList(queryWrapper);
        return result;
    }
}
